package jdklearning.concurrent.thread;



public class LockTest {

	
	 public void testMethod(Object lock){
        try{
            synchronized (lock){
                System.out.println(Thread.currentThread().getName() + " Begin wait()");
                lock.wait();
                System.out.println(Thread.currentThread().getName() + " End wait");
            }
        }
        catch (InterruptedException e){
            e.printStackTrace();
        }
        
//        while(true) {
//        	
//        }
	}
	 
	 public void synNotifyMethod(Object lock){
        try{
            synchronized (lock){
                System.out.println("Begin notify(), ThreadName = " + Thread.currentThread().getName());
                lock.notify();
                Thread.sleep(5000);
                System.out.println("End notify(), ThreadName = " + Thread.currentThread().getName());
            }
        }
        catch (InterruptedException e){
            e.printStackTrace();
        }
	}
	 
	
	class MyThread extends Thread{
		private Object lock;
		
		 public MyThread(Object lock){
		     this.lock = lock;
		 }
		 
		@Override
		public void run() {
			testMethod(lock);
		}
	}
	
	
	class MyThread1 extends Thread{
		private Object lock;
		
		public MyThread1(Object lock){
			this.lock = lock;
		}

		@Override
		public void run() {
			synNotifyMethod(lock);
		}
	}
	
	
	public static void main(String[] args) {
		Object lock = new Object();
		LockTest threadTest = new LockTest();
		Thread mt0 = threadTest.new MyThread(lock);
		Thread mt1 = threadTest.new MyThread1(lock);
	    mt0.start();
	    mt1.start();
	}
}
